﻿<cfsilent>
	<cfscript>
		
		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		
		teacherArray = arrayNew(1);
		rs_teacher = queryNew("tch_id");
		
		keyword = trim(event.getArg('Keywords'));
		
		if ( len(keyword) ) {
			
			sql = "SELECT 
						t_teacher.tch_id, t_teacher.tch_name, t_teacher.tch_sex, 
						t_institute.institute_short 
					FROM 
					  	t_teacher 
					   	INNER JOIN t_institute ON t_institute.institute_id = t_teacher.institute_id 
					WHERE 
					   	t_teacher.tch_id LIKE :keyword 
					   	OR 
					   	t_teacher.tch_name LIKE :keyword 
					ORDER BY 
						t_teacher.tch_name ASC ";
			queryObj = new query( datasource=application.dnsSlave, maxRows=18 );
			queryObj.addParam( name="keyword", value=keyword & '%', cfsqltype="cf_sql_varchar" );
			rs_teacher = queryObj.execute( sql=sql ).getResult(); 
			
			for(a =1 ;a lte rs_teacher.recordCount ;a++){
				arrayAppend(teacherArray,[rs_teacher['tch_id'][a],rs_teacher['tch_name'][a],rs_teacher['tch_sex'][a],rs_teacher['institute_short'][a]]);
			}
		}
		
	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:teacherArray, stringNumbers:true)#</cfoutput>